package cuiyt.offer;

import java.util.ArrayList;
import java.util.Collections;

/**
 * @author cyt
 * @create 2020-05-20 15:26
 */
public class T19_1 {


    /**
     * compareTo
     *
     * Collections.sort
     *
     * 的原理
     * @param args
     */
    public static void main(String[] args) {
        int[] arr = {3, 32, 321};

        String s = "";

        ArrayList<Integer> list = new ArrayList<>();

        int n = arr.length;

        for (int i = 0; i < n; i++) {
            list.add(arr[i]);
        }

        Collections.sort(list,
                (a, b) -> {
                    String s1 = a + "" + b;
                    String s2 = b + "" + a;
                    return s1.compareTo(s2);
                });

        for (int j : list) {
            s += j;
        }

        System.out.println(s);
    }
}
